import json
from flask import Flask
from flask_sqlalchemy import SQLAlchemy



# 创建 db 实例
db = SQLAlchemy()
app = Flask(__name__)



def blueprint_register(app):
    from core.blueprints.edit.login import login_blueprint
    from core.blueprints.edit.personal import personal_blueprint
    from core.blueprints.view.welcome import welcome_blueprint
    from core.blueprints.edit.img import img_blueprint

    app.register_blueprint(welcome_blueprint)
    app.register_blueprint(login_blueprint)
    app.register_blueprint(personal_blueprint)
    app.register_blueprint(img_blueprint)

def create_app():
    with open('config.json') as cf:
        config_data = json.load(cf)
    app.config.update(config_data)

    blueprint_register(app)

    db.init_app(app)
    return app


def create_db():
    with app.app_context():
        from models import User,Comment,Post,Prove,LikePost,LikeUser,LikeComment,Intro,Img
        db.create_all()